// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.bucket;

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.function.Predicate;
import zombie.core.skinnedmodel.ModelManager;
import zombie.core.textures.Texture;

public final class Bucket {
    private String m_name;
    private final HashMap<Path, Texture> m_textures = new HashMap();
    private static final FileSystem m_fs = FileSystems.getDefault();
    private final zombie.PredicatedFileWatcher m_fileWatcher = new zombie.PredicatedFileWatcher(
        (Predicate<String>)(string -> this.HasTexture(string)), string -> {
            Texture texture = this.getTexture(string);
            texture.reloadFromFile(string);
            ModelManager.instance.reloadAllOutfits();
        }
    );

    public Bucket() {
        zombie.DebugFileWatcher.instance.add(this.m_fileWatcher);
    }

    public void AddTexture(Path filename, Texture texture) {
        if (texture != null) {
            this.m_textures.put(filename, texture);
        }
    }

    public void AddTexture(String filename, Texture texture) {
        if (texture != null) {
            this.AddTexture(m_fs.getPath(filename), texture);
        }
    }

    public void Dispose() {
        for (Texture texture : this.m_textures.values()) {
            texture.destroy();
        }

        this.m_textures.clear();
    }

    public Texture getTexture(Path filename) {
        return (Texture)this.m_textures.get(filename);
    }

    public Texture getTexture(String filename) {
        return this.getTexture(m_fs.getPath(filename));
    }

    public boolean HasTexture(Path filename) {
        return this.m_textures.containsKey(filename);
    }

    public boolean HasTexture(String filename) {
        return this.HasTexture(m_fs.getPath(filename));
    }

    String getName() {
        return this.m_name;
    }

    void setName(String string) {
        this.m_name = string;
    }

    public void forgetTexture(String name) {
        this.m_textures.remove(name);
    }
}
